package edu.gdkm.sql.dao;

import edu.gdkm.sql.pojo.Goods;
import org.apache.ibatis.annotations.*;

import java.math.BigDecimal;
import java.util.List;

@Mapper
public interface GoodsMapper {

    @Select("SELECT * FROM vueshop_goods")
    List<Goods> findAll();

    @Select("SELECT * FROM vueshop_goods WHERE id = #{id}")
    @Results(id = "vueshopGoodsResultMap", value = {
            @Result(property = "id", column = "id"),
            @Result(property = "categoryId", column = "category_id"),
            @Result(property = "name", column = "name"),
            @Result(property = "price", column = "price"),
            @Result(property = "picture", column = "picture"),
            @Result(property = "stock", column = "stock"),
            @Result(property = "spec", column = "spec"),
            @Result(property = "description", column = "description")
    })
    Goods findById(@Param("id") Integer id);

    @Insert("INSERT INTO vueshop_goods(category_id, name, price, picture, stock, spec, description) VALUES(#{categoryId}, #{name}, #{price}, #{picture}, #{stock}, #{spec}, #{description})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    void insert(Goods goods);

    @Update("UPDATE vueshop_goods SET category_id=#{categoryId}, name=#{name}, price=#{price}, picture=#{picture}, stock=#{stock}, spec=#{spec}, description=#{description} WHERE id=#{id}")
    void update(Goods goods);

    @Delete("DELETE FROM vueshop_goods WHERE id=#{id}")
    void delete(@Param("id") Integer id);
}
